﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace greenbelt
{
    public partial class QianUser_StartExamfra : System.Web.UI.Page
    {
        //Datacon dataconn = new Datacon();
        static int int_row1 = 0;  //单选题题号索引
        static int int_row2 = 0;  //多选题题号索引
        static int int_row1Point = 0;//单选题分数
        static int int_row2Point = 0;//多选题分数
        //DataSet myds3;    //预定义保存问答题的DataSet，以便在页面结束时统一关闭DataSet。但是若用户强行关闭页面，不知道DataSet是否随之关闭
        //============页面加载事件，从数据库中提取题目---本程序从mydesk.aspx中调用.================
        protected void Page_Load(object sender, EventArgs e)
        {


            if (!IsPostBack)    //事实上,当用户刷新屏幕时,IsPostBack的值为false.因此不能用它来判断是否刷新屏幕.zxd2008-7-31
            {
                //以下从父页面移动过来
                //以下判断考生是初次测试(tb_StuResult中无该课、该考生的记录\补考tb_StuResult中已经有一条记录\重复测试（tb_StuResult已有2条记录）
                //首先判断tb_StuResult表中是否已有本人本课程记录。如果有且总分大于59分
                Conn zconn = new Conn();
                string zxdsql = "select count(stu_username),max(res_total) from tb_StuResult where stu_username='" + Session["sUserName"].ToString() + "' and kecheng_id=" + Session["skaoshiid"].ToString();
                string zresu = zconn.sqlTwo(zxdsql);
                zconn.Dispose();
                if (zresu.Substring(0, 1) == "0")
                {
                    //该考生还没有参加本课程测试，可以正常进入
                    //先添加1条记录到tb_StuResult表
                    string zxtsj1 = DateTime.Now.ToString();
                    zxdsql = "insert into tb_StuResult " +
                         "(stu_username,stu_username1,kecheng_id,kecheng,taotiid,res_xtsj)"
                                + "values('" + Session["sUserName"].ToString() + "','" + Session["sUserName1"].ToString() + "'," + Session["skaoshiid"].ToString() + ",'" + Session["skaoshiname"].ToString() + "',"
                            + Session["skaoshitaoti"].ToString() + ",'" + zxtsj1 + "')";
                    zconn.ExeSql(zxdsql);
                    zxdsql = "select res_id from tb_StuResult where stu_username='" + Session["sUserName"].ToString() + "' and kecheng_id=" + Session["skaoshiid"].ToString() + " and res_xtsj='" + zxtsj1 + "'";
                    Conn zconn0807 = new Conn();
                    Session["skaoshitimuid"] = zconn0807.sqlFirst(zxdsql);                  //学生进入测试前,添加一条记录.变量记录该记录的id号.即res_id
                    zconn0807.Dispose();
                }
                else   //参加测试的次数大于0
                {
                    int zresu1 = Int16.Parse(zresu.Substring(0, zresu.IndexOf("|"))); //参加测试的次数
                    int zresu2 = Int16.Parse(zresu.Substring(zresu.IndexOf("|") + 1));//最高分
                    
                    if (zresu1 > 1)      //参加测试的次数2次或者2次以上---一旦排除正常刷新屏幕情况，则视为多次测试。
                        //对于参加过一次测试的人，在下边的判断中进行处理
                    {
                        //以下判断刷屏，注意，目前程序关于刷屏还有bug，刷几次屏幕之后，点击交卷，出现错误，超出界限--已解决,变量未清0
                        //通过判断已经存在了2条记录且（其中一条记录的xtsj为本日），且（差距不超过1小时），且（总分为0）则视为刷屏，
                        //刷屏的仍然显示上次随机选择的体套（记录在tb_StuResult表中。）
                        //是否可以简化为，利用Session["skaoshitimuid"] = ""的属性？
                        if (!(Session["skaoshitimuid"] == null))
                        {
                           
                            if (Session["skaoshitaoti"].ToString() == "")
                            {
                                //如果不属于刷屏，则视为多次参加测试，退出。
                                Session["skaoshiid"] = null;
                                Session["skaoshiname"] = null;
                                Session["skaoshitaoti"] = null;
                                Session["skaoshishijian"] = null;
                                Session["sScoreDanxuan"] = null;   //退出前，释放相关session变量
                                Session["sScoreDuoxuan"] = null;
                                Session["sScoreWenda"] = null;
                                Session["skaoshitimuid"] = null;
                                Response.Write("<script language=javascript>alert('您已经参加了多次自我测试，该休息一下了。');if(opener!=null){opener.location.reload();window.close();}</script>");
                                //Response.Write("<script lanuage=javascript>window.close();location='javascript:history.go(-1)'</script>");
                                Response.Write("<script language='javascript'>window.opener=null;window.close();</script>");
                                Response.End();

                            }
                            Conn zconn0807161 = new Conn();
                            zxdsql = "select taotiid from tb_StuResult where res_id=" + Session["skaoshitimuid"].ToString();
                            Session["skaoshitaoti"] = zconn0807161.sqlFirst(zxdsql);
                            //对于刷屏的情况，要重新计算session变量：
                            zxdsql = "select sum(score) from tb_questions where (que_lessonid=" + Session["skaoshiid"].ToString() + "and que_taotiid=" + Session["skaoshitaoti"].ToString() + " and que_type='单选题')";
                            Session["sScoreDanxuan"] = zconn0807161.sqlFirst(zxdsql);    //当没找到相关记录时，返回'0'，恰好是需要的结果。
                            zxdsql = "select sum(score) from tb_questions where (que_lessonid=" + Session["skaoshiid"].ToString() + "and que_taotiid=" + Session["skaoshitaoti"].ToString() + " and que_type='多选题')";
                            Session["sScoreDuoxuan"] = zconn0807161.sqlFirst(zxdsql);
                            zxdsql = "select sum(score) from tb_questions where (que_lessonid=" + Session["skaoshiid"].ToString() + "and que_taotiid=" + Session["skaoshitaoti"].ToString() + " and que_type='问答题')";
                            Session["sScoreWenda"] = zconn0807161.sqlFirst(zxdsql);


                            
                            zxdsql = "select shijian from tb_TaoTi where LessonID=" + Session["skaoshiid"].ToString().Trim() + "and id=" + Session["skaoshitaoti"].ToString(); //取得课程对应的所有套题
                            Session["skaoshishijian"] = zconn0807161.sqlFirst(zxdsql);  //重置测试时间
                            zconn0807161.Dispose(); //刷屏，可以继续测试！
                        }
                        //判断刷屏结束
                        else
                        {
                            //如果不属于刷屏，则视为多次参加测试，退出。
                            Session["skaoshiid"] = null;
                            Session["skaoshiname"] = null;
                            Session["skaoshitaoti"] = null;
                            Session["skaoshishijian"] = null;
                            Session["sScoreDanxuan"] = null;   //退出前，释放相关session变量
                            Session["sScoreDuoxuan"] = null;
                            Session["sScoreWenda"] = null;
                            Session["skaoshitimuid"] = null;
                            Response.Write("<script language=javascript>alert('您已经参加了多次自我测试，该休息一下了。');if(opener!=null){opener.location.reload();window.close();}</script>");
                            Response.Write("<script>window.parent.close()</script>");
                            //Response.Write("<script>window.close()</script>");

                            //Response.Write("<script language='javascript'>window.opener=null;window.close();</script>");
                            Response.End();
                        }
                    }
                    if (zresu2 == 999)//如果最高分大于59分，为及格，不必再参加测试。总分=999表示有问答题（已考完，等评分）
                    {
                        Session["skaoshiid"] = null;
                        Session["skaoshiname"] = null;
                        Session["skaoshitaoti"] = null;
                        Session["skaoshishijian"] = null;
                        Session["sScoreDanxuan"] = null;   //退出前，释放相关session变量
                        Session["sScoreDuoxuan"] = null;
                        Session["sScoreWenda"] = null;
                        Session["skaoshitimuid"] = null;
                        Response.Write("<script language=javascript>alert('测试正在等待老师评分，不必再试了。');if(opener!=null){opener.location.reload();window.close();}</script>");
                        Response.Write("<script>window.parent.close()</script>");
                        return;
                    }
                    else if (zresu2 > 59)//如果最高分大于59分，为及格，不必再参加测试。总分=999表示有问答题（已考完，等评分）
                    {
                        Session["skaoshiid"] = null;
                        Session["skaoshiname"] = null;
                        Session["skaoshitaoti"] = null;
                        Session["skaoshishijian"] = null;
                        Session["sScoreDanxuan"] = null;   //退出前，释放相关session变量
                        Session["sScoreDuoxuan"] = null;
                        Session["sScoreWenda"] = null;
                        Session["skaoshitimuid"] = null;
                        Response.Write("<script language=javascript>alert('您已经通过了测试，不必再试了。');if(opener!=null){opener.location.reload();window.close();}</script>");
                        Response.Write("<script>window.parent.close()</script>");
                        return;
                    }

                    else if (zresu1 == 1)  //对于参加过一次测试的人，如果上次分数不及格，则允许再参加一次
                    {
                        if (!(Session["skaoshitimuid"] == null))    //未考虑==null的情况,并且---为什么!=null才算补考呢?
                        {

                            if (Session["skaoshitaoti"].ToString() == "")//不是刷屏，出现异常.因为记录测试成绩表记录号的Session变量.参照补考,模拟出一套题目来!
                            {
                                //补考，也可以正常进入，但不允许选择测试时选择的题套
                                //先添加1条记录到tb_StuResult表
                                Response.Write("<script language=javascript>alert('您有过一次测试记录，本次测试为补考，您仅有一次补考机会。。。。。');if(opener!=null){opener.location.reload();window.close();}</script>");
                                string zxtsj2 = DateTime.Now.ToString();
                                Conn zconn0807162 = new Conn();
                                zxdsql = "insert into tb_StuResult " +
                                    "(stu_username,stu_username1,kecheng_id,kecheng,taotiid,res_xtsj)"
                                            + "values('" + Session["sUserName"].ToString() + "','" + Session["sUserName1"].ToString() + "'," + Session["skaoshiid"].ToString() + ",'" + Session["skaoshiname"].ToString() + "',"
                                        + Session["skaoshitaoti"].ToString() + ",'" + zxtsj2 + "')";
                                zconn0807162.ExeSql(zxdsql);
                                zxdsql = "select res_id from tb_StuResult where stu_username='" + Session["sUserName"].ToString() + "' and kecheng_id=" + Session["skaoshiid"].ToString() + " and res_xtsj='" + zxtsj2 + "'";
                                Session["skaoshitimuid"] = zconn0807162.sqlFirst(zxdsql);                  //学生进入测试前,添加一条记录.变量记录该记录的id号.即res_id
                                zconn0807162.Dispose();


                            }
                            Conn zconn0807163 = new Conn();
                            zxdsql = "select taotiid from tb_StuResult where res_id=" + Session["skaoshitimuid"].ToString();
                            Session["skaoshitaoti"] = zconn0807163.sqlFirst(zxdsql);
                            //对于刷屏的情况，要重新计算session变量：
                            zxdsql = "select sum(score) from tb_questions where (que_lessonid=" + Session["skaoshiid"].ToString() + "and que_taotiid=" + Session["skaoshitaoti"].ToString() + " and que_type='单选题')";
                            Session["sScoreDanxuan"] = zconn0807163.sqlFirst(zxdsql);    //当没找到相关记录时，返回'0'，恰好是需要的结果。
                            zxdsql = "select sum(score) from tb_questions where (que_lessonid=" + Session["skaoshiid"].ToString() + "and que_taotiid=" + Session["skaoshitaoti"].ToString() + " and que_type='多选题')";
                            Session["sScoreDuoxuan"] = zconn0807163.sqlFirst(zxdsql);
                            zxdsql = "select sum(score) from tb_questions where (que_lessonid=" + Session["skaoshiid"].ToString() + "and que_taotiid=" + Session["skaoshitaoti"].ToString() + " and que_type='问答题')";
                            Session["sScoreWenda"] = zconn0807163.sqlFirst(zxdsql);
                            zxdsql = "select shijian from tb_TaoTi where LessonID=" + Session["skaoshiid"].ToString().Trim() + " and id=" + Session["skaoshitaoti"].ToString(); //取得课程对应的所有套题
                            Session["skaoshishijian"] = zconn0807163.sqlFirst(zxdsql);  //重置测试时间
                            zconn0807163.Dispose(); //刷屏，可以继续测试！
                        }
                        else
                        {
                            //补考，也可以正常进入，但不允许选择测试时选择的题套
                            //先添加1条记录到tb_StuResult表
                            Response.Write("<script language=javascript>alert('您有过一次测试记录，本次测试为补考，您仅有一次补考机会。。。。。');if(opener!=null){opener.location.reload();window.close();}</script>");
                            string zxtsj2 = DateTime.Now.ToString();
                            Conn zconn0807162 = new Conn();
                            zxdsql = "insert into tb_StuResult " +
                                "(stu_username,stu_username1,kecheng_id,kecheng,taotiid,res_xtsj)"
                                        + "values('" + Session["sUserName"].ToString() + "','" + Session["sUserName1"].ToString() + "'," + Session["skaoshiid"].ToString() + ",'" + Session["skaoshiname"].ToString() + "',"
                                    + Session["skaoshitaoti"].ToString() + ",'" + zxtsj2 + "')";
                            zconn0807162.ExeSql(zxdsql);
                            zxdsql = "select res_id from tb_StuResult where stu_username='" + Session["sUserName"].ToString() + "' and kecheng_id=" + Session["skaoshiid"].ToString() + " and res_xtsj='" + zxtsj2 + "'";
                            Session["skaoshitimuid"] = zconn0807162.sqlFirst(zxdsql);                  //学生进入测试前,添加一条记录.变量记录该记录的id号.即res_id
                            zconn0807162.Dispose();
                        }
                        
                    }


                }

                //判断完毕
                

                lbltotalscore.Text = "满分100分。单选题" + Session["sScoreDanxuan"].ToString() + "分，多选题" + Session["sScoreDuoxuan"].ToString() + "分，问答题" + Session["sScoreWenda"].ToString() + "分";
                if (Int16.Parse(Session["sScoreDanxuan"].ToString()) > 0)
                {
                    lblDanxuanBeizhu.Text = "总分" + Session["sScoreDanxuan"].ToString() + "分，答错不给分";
                    this.getCom(1);//如果单选题总分〉0，绑定并显示单选题
                }
                else
                {
                    DataList1.Visible = false;
                    lblDanxuan.Visible = false;
                    lblDanxuanBeizhu.Visible = false;
                    lblDanxuanBeizhu1.Visible = false;
                    lblDanxuan.Height = 0;
                    lblDanxuanBeizhu.Height = 0;
                    lblDanxuanBeizhu1.Height = 0;
                    DataList1.Height = 0;
                }
                if (Int16.Parse(Session["sScoreDuoxuan"].ToString()) > 0)
                {
                    if (Int16.Parse(Session["sScoreDanxuan"].ToString()) == 0)
                    {
                        lblDuoxuan.Text = "一、多选题（";
                    }
                    lblDuoxuanBeizhu.Text = "总分" + Session["sScoreDuoxuan"].ToString() + "分，答错不给分";
                    this.getCom(2);//绑定并显示多选题
                }
                else
                {
                    DataList2.Visible = false;
                    lblDuoxuan.Visible = false;
                    lblDuoxuanBeizhu.Visible = false;
                    lblDuoxuanBeizhu1.Visible = false;
                    lblDuoxuan.Height = 0;
                    lblDuoxuanBeizhu.Height = 0;
                    lblDuoxuanBeizhu1.Height = 0;
                    DataList2.Height = 0;
                }
                if (Int16.Parse(Session["sScoreWenda"].ToString()) > 0)
                {
                    if (Int16.Parse(Session["sScoreDanxuan"].ToString()) + Int16.Parse(Session["sScoreDuoxuan"].ToString()) == 0)
                    {
                        lblWendaTittle.Text = "一、问答题（";
                    }
                    else
                    {
                        if (Int16.Parse(Session["sScoreDanxuan"].ToString()) == 0 | Int16.Parse(Session["sScoreDuoxuan"].ToString()) == 0)
                        {
                            lblWendaTittle.Text = "二、问答题（";
                        }
                    }
                    lblWendabeizhu.Text = "问答总分" + Session["sScoreWenda"].ToString() + "分，答错不给分";
                    this.getCom(3);//绑定并显示问答题
                }
                else
                {
                    DataList3.Visible = false;
                    DataList3.Height = 0;
                    lblWendaTittle.Visible = false;
                    lblWendaTittle.Height = 0;
                    lblWendabeizhu.Visible = false;
                    lblWendabeizhu.Height = 0;
                    lblWemdaBeizhu1.Visible = false;
                    lblWemdaBeizhu1.Height = 0;

                }
            }
        }
        //=========================提交试卷===========================
        public void btnSubmit_Click(object sender, EventArgs e)
        {
            //学生测试完毕，点击交卷。或者时间到，计时器主动调用该功能。
            //当问答题分数为0时，马上能够得到分数。
            //问答题分数大于0时，只能计算单选和多选题目的分数，总分，需要等到老师在“阅卷”中给出分数后才能得到。
            DataList1.Enabled = false;
            DataList2.Enabled = false;
            DataList3.Enabled = false;
            this.getCom(4);//计算单选题分数
            this.getCom(5);//计算多选题分数
            this.lblTotal.Text = "总分：" + (int_row1Point + int_row2Point);
            this.getCom(6);
            //Response.Write("<script lanuage=javascript>alert('您确定要交卷吗？');localtion='StartExamfra.aspx';</script>");
            this.btnSubmit.Enabled = false;
        }
        //==================执行与数据库的关联操作=====================
        protected void getCom(int i)
        {
            string zkechengid = Session["skaoshiid"].ToString();
            string ztaotiid = Session["skaoshitaoti"].ToString();
            Conn zconn = new Conn();
            string zsql = "";
            switch (i)
            {
                //从数据库中选择单选题
                case 1:

                    zsql = "select * "
                        + "from tb_Questions where que_type='单选题'and que_lessonid='"
                        + zkechengid + "'and que_taotiid='" + ztaotiid + "'order by id desc";
                    zconn = new Conn();
                    DataSet myds1 = zconn.Conn_Send(zsql);
                    zconn.Dispose();
                    DataList1.DataSource = myds1;
                    DataList1.DataBind();
                    //生成单选题题号
                    for (int tID1 = 1; tID1 <= DataList1.Items.Count; tID1++)
                    {
                        Label lblSelect = (Label)DataList1.Items[tID1 - 1].FindControl("Label2");
                        lblSelect.Text = tID1.ToString() + "、";
                    }
                    break;
                //从数据库中选择多选题
                case 2:
                    zsql = "select * "
                        + "from tb_Questions where que_type='多选题'and que_lessonid='"
                        + zkechengid + "'and que_taotiid='" + ztaotiid + "'order by id desc";
                    zconn = new Conn();
                    DataSet myds2 = zconn.Conn_Send(zsql);
                    zconn.Dispose();
                    DataList2.DataSource = myds2;
                    DataList2.DataBind();
                    //生成多选题题号
                    for (int tID2 = 1; tID2 <= DataList2.Items.Count; tID2++)
                    {
                        Label lblDSelect = (Label)DataList2.Items[tID2 - 1].FindControl("Label24");
                        lblDSelect.Text = tID2.ToString() + "、";
                    }
                    break;
                case 3:
                    zsql = "select * "
                        + "from tb_Questions where que_type='问答题'and que_lessonid='"
                        + zkechengid + "'and que_taotiid='" + ztaotiid + "'order by id desc";
                    zconn = new Conn();
                    DataSet myds3 = zconn.Conn_Send(zsql);  //已经在页面前边预定义。
                    zconn.Dispose();
                    DataList3.DataSource = myds3;
                    DataList3.DataBind();
                    //生成问答题题号
                    for (int tID2 = 1; tID2 <= DataList3.Items.Count; tID2++)
                    {
                        Label lblDSelect = (Label)DataList3.Items[tID2 - 1].FindControl("Labelwd");
                        lblDSelect.Text = tID2.ToString() + "、";
                    }
                    break;
                //核对单选题答案
                case 4:
                   

                    zsql = "select id,que_answer "
                        + "from tb_Questions where que_type='单选题'and que_lessonid='"
                        + zkechengid + "'and que_taotiid='" + ztaotiid + "'order by id desc";
                    zconn = new Conn();
                    DataSet mydsAnswer1 = zconn.Conn_Send(zsql);
                    zconn.Dispose();
                    //SqlDataAdapter myadapter3 = new SqlDataAdapter("select id,que_answer"
                    //    + " from tb_Questions where que_type='单选题'and que_lessonid='"
                    //    + dd1 + "'and que_taotiid='" + dd2 + "'order by id desc", con);
                    //DataSet myds3 = new DataSet();
                    //myadapter3.Fill(myds3);
                    DataRow[] row1 = mydsAnswer1.Tables[0].Select();
                    //计算单选题成绩
                    int_row1 = 0;  //单选题题号索引
                    int_row1Point = 0;  //单选题的总分
                    foreach (DataRow answer1 in row1)
                    {
                        int_row1 += 1;
                        RadioButtonList rbl = (RadioButtonList)(DataList1.Items[int_row1 - 1].FindControl("RadioButtonList1"));
                        Label lblnoth = (Label)(DataList1.Items[int_row1 - 1].FindControl("lblDanxuanScore"));//记录每题的分数

                        if (rbl.SelectedValue == "")
                        {
                            //this.lblSel.Text = "单选题：0分";
                        }
                        else
                        {
                            if (answer1["que_answer"].ToString().Trim() == rbl.SelectedValue.ToString().Trim())
                            {
                                int_row1Point += Int16.Parse(lblnoth.Text);

                                this.lblSel.Text = "单选题：" + int_row1Point.ToString() + "分";
                            }
                        }
                    }
                    mydsAnswer1.Dispose();  //处理完毕，关闭dataset
                    break;
                //核对多选题答案
                case 5:
                    zsql = "select id,que_answer "
                        + "from tb_Questions where que_type='多选题'and que_lessonid='"
                        + zkechengid + "'and que_taotiid='" + ztaotiid + "'order by id desc";
                    
                    zconn = new Conn();
                    DataSet mydsAnswer2 = zconn.Conn_Send(zsql);
                    zconn.Dispose();
                    //SqlDataAdapter myadapter4 = new SqlDataAdapter("select id,que_answer"
                    //    + " from tb_Questions where que_type='多选题'and que_lessonid='"
                    //    + dd1 + "'and que_taotiid='" + dd2 + "'order by id desc", con);
                    //DataSet myds4 = new DataSet();
                    //myadapter4.Fill(myds4);
                    DataRow[] row2 = mydsAnswer2.Tables[0].Select();
                    //计算多选题成绩
                    int_row2 = 0;  //多选题题号索引
                    int_row2Point = 0;  //多选题的总分，清零
                    foreach (DataRow answer2 in row2)
                    {
                        int_row2 += 1;
                        CheckBoxList cbl = (CheckBoxList)(DataList2.Items[int_row2 - 1].FindControl("CheckBoxList1"));
                        Label lblnoth2 = (Label)(DataList2.Items[int_row2 - 1].FindControl("lblDuoxuanScore"));//记录每题的分数
                        if (cbl.SelectedValue == "")
                        {
                            //lblDSel.Text = "多选题：0分";
                        }
                        else
                        {
                            for (int q = 0; q < cbl.Items.Count; q++)
                            {
                                if (cbl.Items[q].Selected == true)
                                {
                                    this.TextBox1.Text = TextBox1.Text.Trim() + cbl.Items[q].Value + ", ";
                                }
                            }
                            if (answer2["que_answer"].ToString().Trim() == this.TextBox1.Text.Trim())
                            {
                                int_row2Point += Int16.Parse(lblnoth2.Text);
                                this.lblDSel.Text = "多选题：" + int_row2Point.ToString() + "分";
                            }
                            TextBox1.Text = "";
                        }
                    }
                    mydsAnswer2.Dispose();
                    break;

                case 6: //把测试结果插入数据库
                    {
                        string zpingjia = "";
                        int s_total = int_row1Point + int_row2Point;
                        if (s_total >= 0 && s_total < 10)
                        {
                            zpingjia = "一无所知";
                        }
                        if (s_total >= 10 && s_total < 30)
                        {
                            zpingjia = "未入门墙";
                        }
                        if (s_total >= 30 && s_total < 60)
                        {
                            zpingjia = "略知皮毛";
                        }
                        if (s_total >= 60 && s_total < 80)
                        {
                            zpingjia = "初窥门径";
                        }
                        if (s_total >= 80 && s_total < 100)
                        {
                            zpingjia = "颇有心得";
                        }
                        if (s_total == 100)
                        {
                            zpingjia = "登堂入室";
                        }

                        //注意：在StartExamframain.aspx中已经定义了记录本次测试成绩的tb_StuResult表中的res_id值。因此不用insert而是用update
                        //zxdsql = "select res_id from tb_StuResult where stu_username='" + Session["sUserName"].ToString() + "' and kecheng_id=" + Session["skaoshiid"].ToString() + " and res_xtsj='" + zxtsj + "'";
                        //Session["skaoshitimuid"] = zconn.sqlFirst(zxdsql);                  //学生进入测试前,添加一条记录.变量记录该记录的id号.即res_id

                        if (Int16.Parse(Session["sScoreWenda"].ToString()) == 0)  //没问答题
                        {
                            //zsql = "insert into tb_StuResult"
                            //    + "(stu_username,stu_username1,kecheng_id,kecheng,taotiid,res_single,res_more,res_xtsj,res_total,pingjia)"
                            //    + "values('" + Session["sUserName"].ToString() + "','" + Session["sUserName1"].ToString() + "'," + Session["skaoshiid"].ToString() + ",'" + Session["skaoshiname"].ToString() + "',"
                            //+ Session["skaoshitaoti"].ToString() + "," + int_row1Point + "," + int_row2Point + ",'" + DateTime.Now + "'," + (int_row1Point + int_row2Point) +",'"+zpingjia+ "')";
                            zsql = "update tb_StuResult set res_single=" + int_row1Point + ",res_more=" + int_row2Point + ",res_total=" + s_total + ",pingjia='" + zpingjia + "' where res_id=" + Session["skaoshitimuid"].ToString();
                            
                            if (s_total >= 60 && s_total <= 100)
                            {
                                string kaoshiid = Session["skaoshiid"].ToString();
                                string xsql = "select kecheng,kechenged from account where username='" + Session["sUserName"].ToString() + "'";
                                SqlDataReader Reader = DbHelper.ExecuteReader(CommandType.Text, xsql, null);

                                Reader.Read();
                                string kecheng = Reader.GetValue(0).ToString();
                                string kechenged = Reader.GetValue(1).ToString();
                                Reader.Close();

                                kechenged = kechenged + "," + kaoshiid + ",";
                                string[] ske = kecheng.Split(new char[] { ',' });
                                string nkecheng = ",";
                                foreach (string item in ske)
                                {
                                    if (item != kaoshiid && item != "")
                                    {
                                        nkecheng += "," + item + ",";
                                    }
                                }
                                string zzsql = "update account set [kechenged]='" + kechenged + "',[kecheng]='" + nkecheng + "' where [username]='" + Session["sUserName"].ToString() + "'";
                                zconn.ExeSql(zzsql);
                                Session["sKecheng"] = nkecheng;
                                Session["sKechenged"] = kechenged;
                            }
                        }
                        else//如果有问答题,则总分设定为999,以便老师阅卷评分时标识.
                        {
                            //zsql = "insert into tb_StuResult"
                            //    + "(stu_username,stu_username1,kecheng_id,kecheng,taotiid,res_single,res_more,res_xtsj,res_total)"
                            //    + "values('" + Session["sUserName"].ToString() + "','" + Session["sUserName1"].ToString() + "'," + Session["skaoshiid"].ToString() + ",'" + Session["skaoshiname"].ToString() + "',"
                            //+ Session["skaoshitaoti"].ToString() + "," + int_row1Point + "," + int_row2Point + ",'" + DateTime.Now + "',999)";
                            zsql = "update tb_StuResult set res_single=" + int_row1Point + ",res_more=" + int_row2Point + ",res_total=999 where res_id=" + Session["skaoshitimuid"].ToString();
                        }
                        zconn = new Conn();
                        int noth080630 = zconn.ExeSql(zsql);
                        zconn.Dispose();
                        if (noth080630 == 0)
                        {
                            Response.Write("<script language=javascript>alert('很抱歉地通知您,您的自我测试成绩未提交成功,请联络老师或者系统管理员安排重新测试事宜！！');if(opener!=null){opener.location.reload();window.close();}</script>");
                            return;
                        }
                        if (noth080630 == 1 && Int16.Parse(Session["sScoreWenda"].ToString()) == 0) //提交成功,且没有问答题.立即显示分数.
                        {
                            Response.Write("<script language=javascript>alert('操作正确,自我测试提交成功！！');if(opener!=null){opener.location.reload();window.close();}</script>");
                        }
                        zsql = "select * "
                        + "from tb_Questions where que_type='问答题'and que_lessonid='"
                        + zkechengid + "'and que_taotiid='" + ztaotiid + "'order by id desc";
                        zconn = new Conn();
                        DataSet myds31 = zconn.Conn_Send(zsql);  //已经在页面前边预定义。
                        zconn.Dispose();
                        if (noth080630 == 1 && Int16.Parse(Session["sScoreWenda"].ToString()) > 0)//提交成功,但有问答题,需等待老师阅卷评分
                        {
                            //在显示成功之前,还要将学生的问答题答案记入表tb_StuResult_wenda
                            for (int tID2 = 1; tID2 <= DataList3.Items.Count; tID2++)
                            {
                                TextBox ztxtanswer = (TextBox)(DataList3.Items[tID2 - 1].FindControl("txtanswer"));//
                                string zsubject = myds31.Tables[0].Rows[tID2 - 1][1].ToString();
                                string zscore0 = myds31.Tables[0].Rows[tID2 - 1][14].ToString(); //该题分值
                                string zanswer = ztxtanswer.Text;
                                string zxtsj1 = DateTime.Now.ToString();
                                zsql = "insert into tb_StuResult_wenda (stu_username,stu_username1,kecheng_id,kecheng,taotiid,xtsj1,que_subject,que_answer,score0)"
                                + "values ('" + Session["sUserName"].ToString() + "','" + Session["sUserName1"].ToString() + "'," + Session["skaoshiid"].ToString() + ",'" + Session["skaoshiname"].ToString() + "'," + Session["skaoshitaoti"].ToString() + ",'" + zxtsj1 + "','" + zsubject + "','" + zanswer + "'," + zscore0 + ")";
                                noth080630 = zconn.ExeSql(zsql);

                            }
                            //记录完毕
                            Response.Write("<script language=javascript>alert('自我测试提交成功,请等待老师阅卷后查询分数');if(opener!=null){opener.location.reload();window.close();}</script>");
                        }
                    }
                    break;
            }
            //试图在此处关闭myds1-3,但是语法自动提示不显示这3个变量，是否意味着系统自动关闭？

        }
        //========================退出当前系统========================
        protected void btnExit_Click(object sender, EventArgs e)
        {
            Session["skaoshiid"] = null;
            Session["skaoshiname"] = null;
            Session["skaoshitaoti"] = null;
            Session["skaoshishijian"] = null;
            Session["sScoreDanxuan"] = null;   //退出前，释放相关session变量
            Session["sScoreDuoxuan"] = null;
            Session["sScoreWenda"] = null;
            Session["skaoshitimuid"] = null;
            //Response.Write("<script lanuage=javascript>window.close();location='javascript:history.go(-1)'</script>");
            Response.Write("<script>window.parent.close()</script>");

        }
    }
}